package com.xhwl.logistics.enums;

import com.xhwl.common.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Getter
@AllArgsConstructor
public enum VehicleTimeRangeEnum {

    TODAY("当天"),
    YESTERDAY("昨天"),
    THIS_MONTH("当月");

    private static final Map<String, VehicleTimeRangeEnum> map;
    static {
        map = new HashMap<>();
        for (VehicleTimeRangeEnum vehicleTimeRangeEnum : VehicleTimeRangeEnum.values()) {
            map.put(vehicleTimeRangeEnum.getDescription(), vehicleTimeRangeEnum);
        }
    }

    private String description;

    public static VehicleTimeRangeEnum toVehicleTimeRangeEnum(String description) {
        return Optional.ofNullable(map.get(description)).orElseThrow(() -> new BusinessException("非法的VehicleTimeRange"));
    }

}
